/*
* UDPdriver.h
* Author: Zhong Ming
* Data: 20171016
*/

#ifndef UDPDRIVER_H
#define UDPDRIVER_H

#include <stdio.h>

typedef struct{
	void* buffer;
	unsigned int bytes;
	char local_ip[64];
	char remote_ip[64];
	unsigned int local_port;
	unsigned int remote_port;
} UDPdriver_Data;

class CUDPdriver
{
public:
	CUDPdriver(void);
	~CUDPdriver(void);

	/*
	 * listen() 
	 * Discription: Listen to local port
	 * Return  : success -> 0, fail -> -1
	 */
	int listen(unsigned int port, void* options = NULL);


	/*
	* connect() 
	* Discription: Connect to remote ip & port
	* Return  : success -> 0, fail -> -1
	*/
	int connect(char* remote_ip, unsigned int remote_port, void* options = NULL);
	/*
	* connect() 
	* Discription: Connect to remote ip & port with local port
	* Return     : success -> 0, fail -> -1
	*/
	int connect(char* remote_ip, unsigned int remote_port, unsigned int local_port, void* options = NULL);

	/*
	* send_data() 
	* Discription: After connect(or recv once after listen), send packet to latest remote port
	* Return  : success -> bytes sent, fail -> -1
	*/
	int send_data(void* buf, unsigned int bytes);
	/*
	* send_data_with_ip() 
	* Discription: Send packet to any remote
	* Return  : success -> bytes sent, fail -> -1
	*/
	int send_data_with_ip(void* buf, unsigned int bytes, char* remote_ip, unsigned int remote_port);


	/*
	* recv_data() 
	* Discription: recv data
	* Return  : success -> bytes recved, fail -> -1
	*/
	int recv_data(void *buffer, unsigned int bytes);
	/*
	* recv_data_with_ip() 
	* Discription: recv data with ip
	* Return  : success -> bytes recved, fail -> -1
	*/
	int recv_data_with_ip(UDPdriver_Data *recv);

private:
	/* 
	 *         internal use only
	 * do not try to access this structure
	 */
	struct CUDPdriver_priv;
	struct CUDPdriver_priv* priv;
};

#endif // UDPDRIVER_H